package com.zhangyu.shadow.repair.delegate.luncher;

import com.zhangyu.shadow.repair.base.IStringDataConvert;
import com.zhangyu.shadow.repair.config.ErrorMsg;
import com.zhangyu.shadow.repair.delegate.bean.SetInfoBean;
import com.zhangyu.shadow.repair.manager.AccountManager;

import org.greenrobot.greendao.annotation.NotNull;

import st.lib.base.net.callback.IError;

/**
 * Description:
 *
 * @author Hequn.Lee
 * @date 2018/11/5
 */
public class LauncherPresenter extends LauncherContract.Presenter {

    private final LauncherContract.View mView;
    private final LauncherContract.Model mModel;

    public LauncherPresenter(@NotNull LauncherContract.View view) {
        mView = view;
        mModel = new LauncherModel();
    }

    @Override
    void getPersonInfo() {
        addDisposable(mModel.getPersonInfo(new IStringDataConvert<SetInfoBean>() {
                    @Override
                    public void convert(SetInfoBean infoBean) {
                        if (infoBean != null) {
                            if (mView != null) {
                                mView.getPersonInfoSucceed(infoBean);
                            }
                        } else {
                            if (mView != null) {
                                mView.getPersonInfoFailed(-1, ErrorMsg.ERROR_DATA);
                            }
                        }
                    }
                }, new IError() {
                    @Override
                    public void onError(int code, String msg) {
                        if (mView != null) {
                            mView.getPersonInfoFailed(code, msg);
                        }
                    }
                })
        );
    }

    @Override
    void getCanEditTime() {
        addDisposable(mModel.getCanEditTime(new IStringDataConvert<String>() {
                    @Override
                    public void convert(String isCan) {
                        AccountManager.getInstance().setCanEditTime(isCan);
                    }
                }, new IError() {
                    @Override
                    public void onError(int code, String msg) {

                    }
                })
        );
    }
}
